package cn.itcast.exception;

import cn.itcast.pojo.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@RestControllerAdvice //包含了@Component 和 @ResponseBody
@Component
public class MyExceptionHandledAdvice {
    @ExceptionHandler(IOException.class)
    public Result handleIoException(IOException e) {
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public Result handleArrayIndexOutOfBoundsException(ArrayIndexOutOfBoundsException e) {
        return Result.error("您出现索引越界异常了");
    }




    @ExceptionHandler(IndexOutOfBoundsException.class)
    public Result handleIndexOutOfBoundsException(IndexOutOfBoundsException e) {
        return Result.error(e.getMessage());
    }


    @ExceptionHandler(NullPointerException.class)
    public Result handleNullPointerException(NullPointerException e) {
        return Result.error(e.getMessage());
    }


}
